package com.bob.idea.gui.action;


import com.bob.common.DataStore;
import com.bob.common.utils.FileUtil;
import org.apache.commons.lang3.time.DateFormatUtils;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Date;

public class FileChooserActionListener extends DefaultActionListener  {

    @Override
    public void actionPerformed(ActionEvent e) {
        super.actionPerformed(e);
        JFileChooser fileChooser = (JFileChooser)e.getSource();
        int v = fileChooser.getDialogType();
        if(v == JFileChooser.APPROVE_OPTION){
            File selectedFile = fileChooser.getSelectedFile();
            fileChooser.setCurrentDirectory(selectedFile);
            System.out.println("absolutePath========================"+selectedFile.getAbsolutePath());
            DataStore.getDataStore().setPatchOutPath(selectedFile);
            GitPatchGeneratorExt.initPatchOutPath(selectedFile);
        }


    }
    static class GitPatchGeneratorExt extends com.bob.common.GitPatchGenerator{
        public static File initPatchOutPath(File patchOutPath){
            DataStore.getDataStore().setPatchOutPath(new File(patchOutPath +File.separator+ DateFormatUtils.format(new Date(), "yyyy-MM-dd-hh-mm-ss")));
            return DataStore.getDataStore().getPatchOutPath();
        }
    }

}

